<?php
include('includes/connexion.php');
$adminmanager = new AdminManager($connexion);
$elevemanager = new EleveManager($connexion);
session_start();
include('includes/secu.php');

$resultatmanager = new ResultatManager($connexion);
$testmanager = new TestManager($connexion);
$reponsemanager = new ReponseManager($connexion);
$exercicemanager = new ExerciceManager($connexion);
$questionmanager = new QuestionManager($connexion);
$classemanager = new ClasseManager($connexion);
$collegemanager = new CollegeManager($connexion);

$idClasse = $_GET['id'];
$classe = $classemanager->get($idClasse);
?>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
  <title><?php echo "Rapport de résultat de la classe ".$classe->nom()." du ".date("d/m/Y"); ?></title>

  <meta charset="utf-8">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width">

  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,700italic,400,600,700">
  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,300,700">
  <link rel="stylesheet" href="css/font-awesome.min.css">
  <link rel="stylesheet" href="js/libs/css/ui-lightness/jquery-ui-1.9.2.custom.min.css">
  <link rel="stylesheet" href="css/bootstrap.min.css">

    <!-- App CSS -->
  <link rel="stylesheet" href="css/target-admin.css">
  <link rel="stylesheet" href="css/custom.css">


  <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
  <![endif]-->
</head>

<body>

<div class="container">

  <div class="content">

    <div class="content-container">
	<br><br>
      
      <div class="row">
        <div style="float:left;">
        <?php echo "Le ".date("d/m/Y")."<br>Classe : ".$classe->nom()."<br>Collège : ".$collegemanager->get($classe->idRefCollege())->nom(); ?>
        </div>
        
        <div align="right">14, rue Romarin<br>69001 LYON<br>Tél : 04 78 28 07 01<br>Fax : 04 78 30 17 22<br>accueil@centreorientationscolaire.fr<br></div>     
      </div>
      
		<hr><div class="content-header-title" align="center">Centre d'Orientation Scolaire</div><hr>

<?php 	$type = array();
		foreach($resultatmanager->ListExerciceClasse($idClasse) as $ex)
		{
			$exo = $exercicemanager->get($ex);
			if($exo->idRefExemple() == 0)
			{
				$type[] = $exo->type();
			}
		} 
		$verbal = false;
		$logique = false;
		$numerique = false;
		$spatial = false;
		foreach($type as $typ)
		{
			if($typ == 'R' || $typ == 'A' || $typ == 'TT')
				$verbal = true;
			if($typ == 'D')
				$logique = true;
			if($typ == 'SN')
				$numerique = true;
			if($typ == 'BB')
				$spatial = true;
		}

if($verbal || $logique){ ?>
				        
              <table 
                class="table table-striped table-bordered table-hover table-highlight table-checkable" 
                data-provide="datatable" 
                data-display-rows="10"
                data-info="false"
                data-search="false"
                data-length-change="true"
                data-paginate="false"
              >
                  <tbody>
                  <tr>
                  <?php if($verbal){?><td width="50%"><h4>Aptitudes verbales, maitrise de la langue</h4></td><?php } ?>
                  <?php if($logique){?><td width="50%"><h4>Aptitude au raisonnement abstrait</h4></td><?php } ?>
                  </tr>
                  <tr>
                  <?php if($verbal){?><td width="50%"><div id="vertical-chart-verbal" class="chart-holder" style="height:400px;"></div></td><?php } ?>
                  <?php if($logique){?><td width="50%"><div id="vertical-chart-logique" class="chart-holder" style="height:400px;"></div></td><?php } ?>
                  </tr>
                  </tbody>
                </table>		
<?php }
if($numerique || $spatial){ ?>
				        
              <table 
                class="table table-striped table-bordered table-hover table-highlight table-checkable" 
                data-provide="datatable" 
                data-display-rows="10"
                data-info="false"
                data-search="false"
                data-length-change="true"
                data-paginate="false"
              >
                  <tbody>
                  <tr>
                  <?php if($numerique){?><td width="50%"><h4>Aptitude au raisonnement numérique</h4></td><?php } ?>
                  <?php if($spatial){?><td width="50%"><h4>Aptitude au raisonnement logique concret</h4></td><?php } ?>
                  </tr>
                  <tr>
                  <?php if($numerique){?><td width="50%"><div id="vertical-chart-numerique" class="chart-holder" style="height:400px;"></div></td><?php } ?>
                  <?php if($spatial){?><td width="50%"><div id="vertical-chart-spatial" class="chart-holder" style="height:400px;"></div></td><?php } ?>
                  </tr>
                  </tbody>
                </table>		
<?php } ?>
    </div> <!-- /.content-container -->
      
  </div> <!-- /.content -->

</div> <!-- /.container -->

  <script src="js/libs/jquery-1.10.1.min.js"></script>
  <script src="js/libs/jquery-ui-1.9.2.custom.min.js"></script>
  <script src="js/libs/bootstrap.min.js"></script>

  <!--[if lt IE 9]>
  <script src="./js/libs/excanvas.compiled.js"></script>
  <![endif]-->
  
  <!-- Plugin JS -->
  <script src="js/plugins/flot/jquery.flot.js"></script>
  <script src="js/plugins/flot/jquery.flot.orderBars.js"></script>
  <script src="js/plugins/flot/jquery.flot.pie.js"></script>
  <script src="js/plugins/flot/jquery.flot.stack.js"></script>
  <script src="js/plugins/flot/jquery.flot.tooltip.min.js"></script>
  <script src="js/plugins/flot/jquery.flot.resize.js"></script>

  <!-- App JS -->
  <script src="js/target-admin.js"></script>

<?php 	if($verbal){
	/*Réponse juste*/
	$reponseJuste = array();
	$reponseJusteTx = array();
	foreach($resultatmanager->getByClasse($idClasse) as $resByClasse)
	{
		$reponseJuste[$resByClasse->idRefEleve()] = 0;
		$reponseJusteTx[$resByClasse->idRefEleve()] = 0;
	}
	$nb_rep_juste = 0;
	
	foreach($resultatmanager->getByClasse($idClasse) as $resByClasse)
	{
		if($resultatmanager->getExercice($resByClasse->id())->type() == 'R' || $resultatmanager->getExercice($resByClasse->id())->type() == 'A' || $resultatmanager->getExercice($resByClasse->id())->type() == 'TT') 
		{	
			if($reponsemanager->get($resByClasse->idRefReponse())->correcte() == 1)
			{
				$reponseJuste[$resByClasse->idRefEleve()]++;
			}
		}
	}
	
	foreach($resultatmanager->ListExerciceClasse($idClasse) as $ex)
	{
		$nb_rep_juste += $exercicemanager->getNbReponseJuste($ex);
	}
	
	$zero=$un=$deux=$trois=$quatre=$cinq=$six=$sept=$huit=$neuf=$dix=0;
	foreach($reponseJuste as $key => $value)
	{
		$reponseJuste[$key] = number_format(($value / $nb_rep_juste) * 100,2);
		$value = $reponseJuste[$key];
		/*Construction du graphe*/
		if($value == 0)
		{
			$zero++;
		}
		if($value > 0 && $value <= 10)
		{
			$un++;
		}
		if($value > 10 && $value <= 20)
		{
			$deux++;
		}
		if($value > 20 && $value <= 30)
		{
			$trois++;
		}
		if($value > 30 && $value <= 40)
		{
			$quatre++;
		}
		if($value > 40 && $value <= 50)
		{
			$cinq++;
		}
		if($value > 50 && $value <= 60)
		{
			$six++;
		}
		if($value > 60 && $value <= 70)
		{
			$sept++;
		}
		if($value > 70 && $value <= 80)
		{
			$huit++;
		}
		if($value > 80 && $value <= 90)
		{
			$neuf++;
		}
		if($value > 90 && $value <= 100)
		{
			$dix++;
		}
		/************************/
		
	}
	/***************/
	?>  
  <!-- Plugin JS -->
  <script type="text/javascript">
$(function () {

	var d1, data, chartOptions;

	d1 = [
		[0,<?php echo $zero; ?>],
		[10, <?php echo $un; ?>], [20, <?php echo $deux; ?>], [30, <?php echo $trois; ?>], [40, <?php echo $quatre; ?>], [50, <?php echo $cinq; ?>],[60, <?php echo $six; ?>], [70, <?php echo $sept; ?>], [80, <?php echo $huit; ?>], [90, <?php echo $neuf; ?>], [100, <?php echo $dix; ?>]
    ];

    data = [{
    	label: 'Résultat',
    	data: d1
    }];

    chartOptions = {
        xaxis: {
				ticks: [<?php for($i = 0; $i <= 100; $i=$i+10){ echo "[".$i.", '".$i."%'],"; } ?>]
		},
        grid: {
            hoverable: true,
            clickable: false,
            borderWidth: 0
        },
        bars: {
	    	show: true,
	    	barWidth: 5,
            fill: true,
            lineWidth: 0,
            order: true,
            lineWidth: 0,
            fillColor: { colors: [ { opacity: 1 }, { opacity: 1 } ] }
	    },
			legend: {
				show: false
		},
        
        tooltip: true,
        tooltipOpts: {
            content: '%s: %y'
        },
        colors: target_admin.layoutColors
    }


    var holder = $('#vertical-chart-verbal');

    if (holder.length) {
        $.plot(holder, data, chartOptions );
    }


});
</script>
<?php } ?>

<?php 	if($logique){  
	/*Réponse juste*/
	$reponseJuste = array();
	$reponseJusteTx = array();
	foreach($resultatmanager->getByClasse($idClasse) as $resByClasse)
	{
		$reponseJuste[$resByClasse->idRefEleve()] = 0;
		$reponseJusteTx[$resByClasse->idRefEleve()] = 0;
	}
	$nb_rep_juste = 0;
	
	foreach($resultatmanager->getByClasse($idClasse) as $resByClasse)
	{
		if($resultatmanager->getExercice($resByClasse->id())->type() == 'D') 
		{	
			if($reponsemanager->get($resByClasse->idRefReponse())->correcte() == 1)
			{
				$reponseJuste[$resByClasse->idRefEleve()]++;
			}
		}
	}
	
	foreach($resultatmanager->ListExerciceClasse($idClasse) as $ex)
	{
		$nb_rep_juste += $exercicemanager->getNbReponseJuste($ex);
	}
	
	$zero=$un=$deux=$trois=$quatre=$cinq=$six=$sept=$huit=$neuf=$dix=0;
	foreach($reponseJuste as $key => $value)
	{
		$reponseJuste[$key] = number_format(($value / $nb_rep_juste) * 100,2);
		$value = $reponseJuste[$key];
		/*Construction du graphe*/
		if($value == 0)
		{
			$zero++;
		}
		if($value > 0 && $value <= 10)
		{
			$un++;
		}
		if($value > 10 && $value <= 20)
		{
			$deux++;
		}
		if($value > 20 && $value <= 30)
		{
			$trois++;
		}
		if($value > 30 && $value <= 40)
		{
			$quatre++;
		}
		if($value > 40 && $value <= 50)
		{
			$cinq++;
		}
		if($value > 50 && $value <= 60)
		{
			$six++;
		}
		if($value > 60 && $value <= 70)
		{
			$sept++;
		}
		if($value > 70 && $value <= 80)
		{
			$huit++;
		}
		if($value > 80 && $value <= 90)
		{
			$neuf++;
		}
		if($value > 90 && $value <= 100)
		{
			$dix++;
		}
		/************************/
		
	}
	/***************/
	?>  
  <!-- Plugin JS -->
  <script type="text/javascript">
$(function () {

	var d1, data, chartOptions;

	d1 = [
		[0,<?php echo $zero; ?>],
		[10, <?php echo $un; ?>], [20, <?php echo $deux; ?>], [30, <?php echo $trois; ?>], [40, <?php echo $quatre; ?>], [50, <?php echo $cinq; ?>],[60, <?php echo $six; ?>], [70, <?php echo $sept; ?>], [80, <?php echo $huit; ?>], [90, <?php echo $neuf; ?>], [100, <?php echo $dix; ?>]
    ];

    data = [{
    	label: 'Résultat',
    	data: d1
    }];

    chartOptions = {
        xaxis: {
				ticks: [<?php for($i = 0; $i <= 100; $i=$i+10){ echo "[".$i.", '".$i."%'],"; } ?>]
		},
        grid: {
            hoverable: true,
            clickable: false,
            borderWidth: 0
        },
        bars: {
	    	show: true,
	    	barWidth: 5,
            fill: true,
            lineWidth: 0,
            order: true,
            lineWidth: 0,
            fillColor: { colors: [ { opacity: 1 }, { opacity: 1 } ] }
	    },
			legend: {
				show: false
		},
        
        tooltip: true,
        tooltipOpts: {
            content: '%s: %y'
        },
        colors: target_admin.layoutColors
    }


    var holder = $('#vertical-chart-logique');

    if (holder.length) {
        $.plot(holder, data, chartOptions );
    }


});
</script>
<?php } ?>

<?php 	if($numerique){  
	/*Réponse juste*/
	$reponseJuste = array();
	$reponseJusteTx = array();
	foreach($resultatmanager->getByClasse($idClasse) as $resByClasse)
	{
		$reponseJuste[$resByClasse->idRefEleve()] = 0;
		$reponseJusteTx[$resByClasse->idRefEleve()] = 0;
	}
	$nb_rep_juste = 0;
	
	foreach($resultatmanager->getByClasse($idClasse) as $resByClasse)
	{
		if($resultatmanager->getExercice($resByClasse->id())->type() == 'SN') 
		{	
			if($reponsemanager->get($resByClasse->idRefReponse())->correcte() == 1)
			{
				$reponseJuste[$resByClasse->idRefEleve()]++;
			}
		}
	}
	
	foreach($resultatmanager->ListExerciceClasse($idClasse) as $ex)
	{
		$nb_rep_juste += $exercicemanager->getNbReponseJuste($ex);
	}
	
	$zero=$un=$deux=$trois=$quatre=$cinq=$six=$sept=$huit=$neuf=$dix=0;
	foreach($reponseJuste as $key => $value)
	{
		$reponseJuste[$key] = number_format(($value / $nb_rep_juste) * 100,2);
		$value = $reponseJuste[$key];
		/*Construction du graphe*/
		if($value == 0)
		{
			$zero++;
		}
		if($value > 0 && $value <= 10)
		{
			$un++;
		}
		if($value > 10 && $value <= 20)
		{
			$deux++;
		}
		if($value > 20 && $value <= 30)
		{
			$trois++;
		}
		if($value > 30 && $value <= 40)
		{
			$quatre++;
		}
		if($value > 40 && $value <= 50)
		{
			$cinq++;
		}
		if($value > 50 && $value <= 60)
		{
			$six++;
		}
		if($value > 60 && $value <= 70)
		{
			$sept++;
		}
		if($value > 70 && $value <= 80)
		{
			$huit++;
		}
		if($value > 80 && $value <= 90)
		{
			$neuf++;
		}
		if($value > 90 && $value <= 100)
		{
			$dix++;
		}
		/************************/
		
	}
	/***************/
	?>  
  <!-- Plugin JS -->
  <script type="text/javascript">
$(function () {

	var d1, data, chartOptions;

	d1 = [
		[0,<?php echo $zero; ?>],
		[10, <?php echo $un; ?>], [20, <?php echo $deux; ?>], [30, <?php echo $trois; ?>], [40, <?php echo $quatre; ?>], [50, <?php echo $cinq; ?>],[60, <?php echo $six; ?>], [70, <?php echo $sept; ?>], [80, <?php echo $huit; ?>], [90, <?php echo $neuf; ?>], [100, <?php echo $dix; ?>]
    ];

    data = [{
    	label: 'Résultat',
    	data: d1
    }];

    chartOptions = {
        xaxis: {
				ticks: [<?php for($i = 0; $i <= 100; $i=$i+10){ echo "[".$i.", '".$i."%'],"; } ?>]
		},
        grid: {
            hoverable: true,
            clickable: false,
            borderWidth: 0
        },
        bars: {
	    	show: true,
	    	barWidth: 5,
            fill: true,
            lineWidth: 0,
            order: true,
            lineWidth: 0,
            fillColor: { colors: [ { opacity: 1 }, { opacity: 1 } ] }
	    },
			legend: {
				show: false
		},
        
        tooltip: true,
        tooltipOpts: {
            content: '%s: %y'
        },
        colors: target_admin.layoutColors
    }


    var holder = $('#vertical-chart-numerique');

    if (holder.length) {
        $.plot(holder, data, chartOptions );
    }


});
</script>

<?php } ?>

<?php 	if($spatial){  
	/*Réponse juste*/
	$reponseJuste = array();
	$reponseJusteTx = array();
	foreach($resultatmanager->getByClasse($idClasse) as $resByClasse)
	{
		$reponseJuste[$resByClasse->idRefEleve()] = 0;
		$reponseJusteTx[$resByClasse->idRefEleve()] = 0;
	}
	$nb_rep_juste = 0;
	
	foreach($resultatmanager->getByClasse($idClasse) as $resByClasse)
	{
		if($resultatmanager->getExercice($resByClasse->id())->type() == 'BB') 
		{	
			if($reponsemanager->get($resByClasse->idRefReponse())->correcte() == 1)
			{
				$reponseJuste[$resByClasse->idRefEleve()]++;
			}
		}
	}
	
	foreach($resultatmanager->ListExerciceClasse($idClasse) as $ex)
	{
		$nb_rep_juste += $exercicemanager->getNbReponseJuste($ex);
	}
	
	$zero=$un=$deux=$trois=$quatre=$cinq=$six=$sept=$huit=$neuf=$dix=0;
	foreach($reponseJuste as $key => $value)
	{
		$reponseJuste[$key] = number_format(($value / $nb_rep_juste) * 100,2);
		$value = $reponseJuste[$key];
		/*Construction du graphe*/
		if($value == 0)
		{
			$zero++;
		}
		if($value > 0 && $value <= 10)
		{
			$un++;
		}
		if($value > 10 && $value <= 20)
		{
			$deux++;
		}
		if($value > 20 && $value <= 30)
		{
			$trois++;
		}
		if($value > 30 && $value <= 40)
		{
			$quatre++;
		}
		if($value > 40 && $value <= 50)
		{
			$cinq++;
		}
		if($value > 50 && $value <= 60)
		{
			$six++;
		}
		if($value > 60 && $value <= 70)
		{
			$sept++;
		}
		if($value > 70 && $value <= 80)
		{
			$huit++;
		}
		if($value > 80 && $value <= 90)
		{
			$neuf++;
		}
		if($value > 90 && $value <= 100)
		{
			$dix++;
		}
		/************************/
		
	}
	/***************/
	?>  
  <!-- Plugin JS -->
  <script type="text/javascript">
$(function () {

	var d1, data, chartOptions;

	d1 = [
		[0,<?php echo $zero; ?>],
		[10, <?php echo $un; ?>], [20, <?php echo $deux; ?>], [30, <?php echo $trois; ?>], [40, <?php echo $quatre; ?>], [50, <?php echo $cinq; ?>],[60, <?php echo $six; ?>], [70, <?php echo $sept; ?>], [80, <?php echo $huit; ?>], [90, <?php echo $neuf; ?>], [100, <?php echo $dix; ?>]
    ];

    data = [{
    	label: 'Résultat',
    	data: d1
    }];

    chartOptions = {
        xaxis: {
				ticks: [<?php for($i = 0; $i <= 100; $i=$i+10){ echo "[".$i.", '".$i."%'],"; } ?>]
		},
        grid: {
            hoverable: true,
            clickable: false,
            borderWidth: 0
        },
        bars: {
	    	show: true,
	    	barWidth: 5,
            fill: true,
            lineWidth: 0,
            order: true,
            lineWidth: 0,
            fillColor: { colors: [ { opacity: 1 }, { opacity: 1 } ] }
	    },
			legend: {
				show: false
		},
        
        tooltip: true,
        tooltipOpts: {
            content: '%s: %y'
        },
        colors: target_admin.layoutColors
    }


    var holder = $('#vertical-chart-spatial');

    if (holder.length) {
        $.plot(holder, data, chartOptions );
    }


});
</script>
<?php } ?>

</body>
</html>